//165322
//174146
//181857
//179707
//173482
//176345
//182341
//175091
//181051
//185746
//184423
//181122
//179100
//178873
//188545
//180253
//180363...
//180361
//183915
//188420
//188819
//173262
//169545
//173784
//176295
//177241
//170180
//171042
//166520
//
//até rmoura
//


var macro;
var jsLF = "\n";
var i, retcode, errtext;
var MyDelay;
var MyPosts;

var Aldeias;

var espioes;
var cavalariaLeve;
var command;

i = 0;

espioes = 1;
cavalariaLeve = 7;
//command = commandPega();



Aldeias = new Array();

//Q0
//0.1
Aldeias.push("32667");
//0.2
Aldeias.push("31384");

//0.3
Aldeias.push("34672");
//0.4
Aldeias.push("32212");
//0.5
Aldeias.push("31055");
//0.6
Aldeias.push("31124");
//0.7
Aldeias.push("32265");
//0.8
Aldeias.push("35798");
//Q1
//1.1
Aldeias.push("31963");
//1.2
Aldeias.push("32237");
//1.3
Aldeias.push("32216");
//1.4
Aldeias.push("30989");
//1.5
Aldeias.push("30747");
//1.6
Aldeias.push("30966");
//1.7
Aldeias.push("30044");
//1.8
Aldeias.push("30068");
//1.9
Aldeias.push("31383");
//Q2//2.1
Aldeias.push("30746");
//2.2
Aldeias.push("31702");
//2.3
Aldeias.push("30634");
//2.4
Aldeias.push("31415");
//2.5
Aldeias.push("29435");
//2.6
Aldeias.push("31174");
//2.7
Aldeias.push("30476");
//2.8
Aldeias.push("30169");
//2.9
Aldeias.push("31506");
//2.10
Aldeias.push("28316");
//2.11
Aldeias.push("30594");
//2.12
Aldeias.push("29929");
//2.13
Aldeias.push("30268");
//2.14
//Aldeias.push("29281");
//Q3//3.1
Aldeias.push("32127");
//3.2
Aldeias.push("34412");
//3.3
Aldeias.push("32269");
//3.4
Aldeias.push("33382");
//3.5
Aldeias.push("32219");
//3.6
Aldeias.push("30931");
//3.7
Aldeias.push("33925");
//3.8
Aldeias.push("31615");
//Q4//4.1
Aldeias.push("34502");
//4.2
Aldeias.push("34638");
//4.3
//Aldeias.push("36709");
//4.4
Aldeias.push("34537");
//4.5
Aldeias.push("35277");
//4.6
Aldeias.push("35612");
//4.7
Aldeias.push("35269");
//4.8
Aldeias.push("35213");
//Q5
//5.1
Aldeias.push("33794");
//5.2
Aldeias.push("34853");
//5.3
Aldeias.push("34714");
//5.4
Aldeias.push("35847");
//5.5
Aldeias.push("36313");
//5.6
Aldeias.push("35708");
//5.7
Aldeias.push("34343");
//5.8
Aldeias.push("36886");
//5.9
Aldeias.push("34655");
//5.10
Aldeias.push("37651");
//5.11
Aldeias.push("38779");
//Q6
//6.1
Aldeias.push("36496");
//6.2
Aldeias.push("34728");
//6.3
Aldeias.push("35597");
//6.4
Aldeias.push("35253");
//6.5
Aldeias.push("35899");
//6.6
Aldeias.push("34858");
//6.7
Aldeias.push("39146");
//6.8
Aldeias.push("36226");
//Q7
//7.1
Aldeias.push("33375");
//7.2
Aldeias.push("35868");
//7.3
Aldeias.push("31920");
//7.4
Aldeias.push("34008");
//7.5
Aldeias.push("35098");
//7.6
Aldeias.push("34498");
//7.7
Aldeias.push("34363");
//7.8
Aldeias.push("32933");
//7.9
Aldeias.push("34879");
//7.10
Aldeias.push("35623");
//7.11
Aldeias.push("33389");
//7.12
Aldeias.push("34395");
//Q8
//8.1
Aldeias.push("30909");
//8.2
Aldeias.push("32763");
//8.3
Aldeias.push("29980");
//8.4
Aldeias.push("30880");
//8.5
Aldeias.push("29734");




MyDelay = 0;

for (i ; i < Aldeias.length; i++) {
    iimSet("POSTID", Aldeias[i]);
    
    macro = "CODE:";
    macro += "URL GOTO=http://br36.tribalwars.com.br/game.php?village=31611&screen=place&target={{postid}}" + jsLF;
    macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";
    iimPlay(macro);

    var text = iimGetLastExtract();
     
    var numCavalariaLeve = text.substr(text.indexOf("('#unit_input_light')")+23,10);
    numCavalariaLeve = numCavalariaLeve.substr(0,numCavalariaLeve.indexOf(")"));
    numCavalariaLeve = parseInt(numCavalariaLeve);
    //  alert(numCavalariaLeve);

    if(numCavalariaLeve<cavalariaLeve){
        //alert("não ha cavalos suficientes. Necessário "+cavalariaLeve);
        macro = "CODE:";
        macro += "WAIT SECONDS=60" + jsLF;
        iimPlay(macro);
        i--
        continue;
    }

    var numSpy = text.substr(text.indexOf("('#unit_input_spy')")+20,10);
    numSpy = numSpy.substr(0,numSpy.indexOf(")"));
    numSpy = parseInt(numSpy);
    //    alert(numSpy);

    if(numSpy<espioes){
        //alert("não ha espioes. Necessário "+espioes);
        macro = "CODE:";
        macro += "WAIT SECONDS=60" + jsLF;
        iimPlay(macro);
        i--
        continue;

    }


    macro = "CODE:";
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_spy CONTENT="+ espioes + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_light CONTENT=" + cavalariaLeve + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:units_form ATTR=ID:target_attack" + jsLF;
    macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";
    
    iimPlay(macro);

    text = iimGetLastExtract();
    command = text.substr(text.indexOf("action=command&amp;h=")+21,4);
    
    macro = "CODE:";
    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:http://br36.tribalwars.com.br/game.php?village=31611&screen=place&action=command&h="+ command +" ATTR=ID:troop_confirm_go" + jsLF;
    macro += "WAIT SECONDS=" + MyDelay + jsLF;
    

    iimDisplay("Executando "+i);
    
    retcode = iimPlay(macro);
    if (retcode < 0) {              // an error has occured
        errtext = iimGetLastError();
        alert(errtext);
        i--;

    //commandPega();
        
    // break;
    }
}







function commandPega(){
    var macro = "CODE:";
    macro += "URL GOTO=http://br36.tribalwars.com.br/game.php?village=31611&screen=place&target=32667" + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_spy CONTENT="+ espioes + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_light CONTENT=" + cavalariaLeve + jsLF;
    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:units_form ATTR=ID:target_attack" + jsLF;
    //macro += "TAG POS=1 TYPE=BODY ATTR=CLASS:* EXTRACT=HTM";
    macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";
	
    var retcode = iimPlay(macro);

    //retcode = iimPlay(macro);
    	
    var text = iimGetLastExtract();
    text = text.substr(text.indexOf("action=command&amp;h=")+21,4);
    alert(text);
    
    return text;
}

